<?php

namespace app\teacher\model;

use app\common\model\BaseModel;
use think\Model;

class Infomation extends BaseModel
{
    /**
     * 语种资讯
     */
    public static function getRecommendByLanguageId($infoCateId)
    {
        $where = static::whereOnline();
        $where['info_cate_id'] = $infoCateId;
        $where['recommendswitch'] = 1;
        return self::where($where)->order(static::WEIGH_DESC)->select();
    }

    /**
     * 资讯列表
     */
    public static function getByLanguageId($infoCateId, $size = 20)
    {
        return self::where(static::whereOnline())->where('info_cate_id', $infoCateId)->order(static::WEIGH_DESC)->paginate($size);
    }

    /**
     * 其他推荐
     */
    public static function getOther($infomationId, $infoCateId)
    {
        $where = static::whereOnline();
        $where['info_cate_id'] = $infoCateId;
        $where['recommendswitch'] = 1;
        $where['infomation_id'] = ['<>', $infomationId];
        return self::where($where)->order(static::WEIGH_DESC)->limit(2)->select();
    }

    /**
     * 搜索
     */
    public static function search($searchName, $size = 20)
    {
        $where = static::whereOnline();
        if ($searchName) {
            $where['title'] = ['like', "%{$searchName}%"];
        }
        return self::where($where)->order(static::WEIGH_DESC)->paginate($size);
    }
}
